package net.hvacapp.cmvrfforandroid.widget;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.TextView;

import net.hvacapp.cmvrfforandroid.R;


/**
 * listview footer
 *
 * @author hailong.han 下午3:34:06
 */


public class ListViewFooterMore extends LinearLayout {

    public enum ListViewFooterStatus {
        GONE, LOADING, ALL
    }

    private ProgressBar mLoadingPb;
    private TextView mLoadingTv;

    private ListViewFooterStatus mFooterStatus;

    /**
     * @param context
     * @param attrs
     * @param defStyle
     */
    public ListViewFooterMore(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        init();
    }

    /**
     * @param context
     * @param attrs
     */
    public ListViewFooterMore(Context context, AttributeSet attrs) {
        super(context, attrs);
        init();
    }

    /**
     * @param context
     */
    public ListViewFooterMore(Context context) {
        super(context);
        init();
    }

    /**
     *
     */
    private void init() {
        LayoutInflater.from(getContext()).inflate(R.layout.footer_more, this,
                true);
        mLoadingPb = (ProgressBar) findViewById(R.id.pb_loading);
        mLoadingTv = (TextView) findViewById(R.id.tv_loading_content);

        mFooterStatus = ListViewFooterStatus.GONE;
    }

    /**
     * 设置ListView 上拉加载更多状态
     *
     * @param status {@link ListViewFooterStatus}
     */
    public void setListViewFooterStatus(ListViewFooterStatus status) {
        switch (status) {
            case ALL:
                mLoadingPb.setVisibility(View.GONE);
                mLoadingTv.setVisibility(View.VISIBLE);
                mLoadingTv.setText(R.string.loading_no_more);

                mFooterStatus = status;
                break;
            case LOADING:
                mLoadingTv.setVisibility(View.VISIBLE);
                mLoadingPb.setVisibility(View.VISIBLE);
                mLoadingTv.setText(R.string.loading);

                mFooterStatus = status;
                break;
            case GONE:
                mLoadingPb.setVisibility(View.GONE);
                mLoadingTv.setVisibility(View.GONE);

                mFooterStatus = status;
                break;
            default:
                break;
        }
    }


    public ListViewFooterStatus getListViewFooterStatus() {
        return mFooterStatus;
    }
}
